package com.nbjtjc.safe.service.safe;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.safe.SafeDangerInspectRecordMapper;
import com.nbjtjc.safe.model.safe.SafeDangerInspectRecord;
import com.nbjtjc.safe.model.safe.SafeDangerInspectTask;
import com.nbjtjc.safe.model.safe.SafeDangerInspectTaskRecord;
import com.nbjtjc.safe.util.MyShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class SafeDangerInspectRecordServiceImpl {

    @Autowired
    private SafeDangerInspectRecordMapper dangerInspectRecordMapper;
    @Value("${aliyun.oss.domain}")
    private String ossDomain;
    @Transactional(rollbackFor = Throwable.class)
    public Result add(SafeDangerInspectRecord inspectRecord) {
        Result result = new Result();
        inspectRecord.setCreateTime(new Date());
        inspectRecord.setInspectTime(new Date());
        Integer uid= MyShiroUtils.getSessionUser().getUserId();
        inspectRecord.setUid(uid);
        dangerInspectRecordMapper.insertSelective(inspectRecord);
        return result;
    }

    public Result search(SafeDangerInspectRecord inspectRecord){
        Result result=new Result();
        PageHelper.startPage(inspectRecord.getPageCurrent(),inspectRecord.getPageSize());
        Integer uid= MyShiroUtils.getSessionUser().getUserId();
        inspectRecord.setUid(uid);
        List<SafeDangerInspectRecord> inspectRecords= dangerInspectRecordMapper.search(inspectRecord);
        if(CollectionUtil.isNotEmpty(inspectRecords)){

//            comparePicsByInspectListId(taskRecords);
        }
        result.setData(new PageInfo<>(inspectRecords));
        return result;
    }
}
